﻿using System.Data;
using Malu.Entity;
using MaLu.Interfaces;
using System;


namespace MaLu.Data.SqlServer {
    public sealed class SqlFaShare : IFaShare
    {
        public int Count(IDbProvider provider, string where)
        {
            string sql = string.Format("select count([id]) from [FaShare] {0}", where);
            return Convert.ToInt32(SqlHelper.Instance.ExecuteScalar(provider, sql));
        }

        public void Insert(IDbProvider provider, FaShare share)
        {
            IDataParameter[] paras = null;
            string sql = SqlHelper.Instance.CreateInsertSql(share, out paras);
            SqlHelper.Instance.ExecuteNonQuery(provider, sql, paras);
        }
        public void Update(IDbProvider provider, FaShare share)
        {
            IDataParameter[] paras = null;
            string sql = SqlHelper.Instance.CreateUpdateSql(share, out paras);
            SqlHelper.Instance.ExecuteNonQuery(provider, sql, paras);
        }

        public void Delete(IDbProvider provider, int id) {
            string sql = string.Format("delete from [FaShare] where [id]={0}", id);
            SqlHelper.Instance.ExecuteNonQuery(provider, sql);
        }
        public FaShare Get(IDbProvider provider, int id)
        {
            string sql = string.Format("select * from [FaShare] where [id]={0}", id);
            using (IDataReader dr = SqlHelper.Instance.ExecuteDataReader(provider, sql))
            {
                return SqlHelper.Instance.ConvertToEntity<FaShare>(dr);
            }
        }

    }
}
